#ifndef _CMENUBAR_H_
#define _CMENUBAR_H_

#include <buola/widgets/cwidget.h>
#include <buola/utility/uevent.h>

namespace buola { namespace gui {

class CMenuBar : public CWidget
{
public:
    enum
    {
        STYLE_COMMENT=(1<<8),
        STYLE_BOTTOMPOS=(1<<9),
        STYLE_POPUP=(1<<10)
    };

public:
    CMenuBar(PMenu pMenu=nullptr);
    ~CMenuBar();

    void SetIconSize(int pSize);
    int GetIconSize()   {   return mIconSize;   }

    PMenu GetMenu()     {   return mMenu;       }
    int GetTextX()      {   return mTextX;      }
    PMenuItem GetSelected();

protected:
    void ShapeAll();
    void PosAll();

    void RedrawItem(int);

    void SelectItem(int);
    void SelectSubMenu(int);

    void ChangeSelection(int);

public:
////////////// Event handling //////////////
    virtual void OnExpose(const CExposeEvent &pE);
    virtual void OnButtonDown(const CMouseEvent &pE);
    virtual void OnButtonUp(const CMouseEvent &pE);
    virtual void OnMouseMove(const CMouseEvent &pE);
    virtual void OnMouseOut(const CMouseEvent &pE);
    void OnMenuClosed();
    virtual void OnSize(const CGeometryEvent &pE);

    void OnTimer();

    UEvent<void()> eClosed;

protected:
    PMenu mMenu;

    int mSelected;

    int mTextX;

    PMenuBar mSubMenu;
    int mOpenSubMenu;

    int mIconSize;

    bool mPressed;

    CTimer *mTimer;

    std::vector<CSize_d> mItemSize;
    std::vector<CPoint_d> mItemPos;

    img::PFont mFont;
    img::PFont mBoldFont;

////////////////// static data //////////////////
};

/*namespace gui*/ } /*namespace buola*/ }

#endif
